package com.google.android.apps.mytracks.services.sensors;

import com.google.android.apps.mytracks.content.Sensor;

import junit.framework.TestCase;

public class PolarMessageParserTest extends TestCase {

  PolarMessageParser parser = new PolarMessageParser();

  public void testIsValid() {
    byte[] buf = new byte[6];
    assertFalse(parser.isValid(buf));
    buf[0] = (byte) 0xFE;
    assertFalse(parser.isValid(buf));
    buf[1] = (byte) 0x08;
    buf[2] = (byte) 0xF7;
    buf[3] = (byte) 0x0;
    assertTrue(parser.isValid(buf));
  }

  public void testParseBuffer() {
    byte[] buf = new byte[6];
    buf[0] = (byte) 0xFE;
    buf[1] = (byte) 0x08;
    buf[2] = (byte) 0xF7;
    buf[3] = (byte) 0x0;
    buf[5] = (byte) 0x96;
    Sensor.SensorDataSet sds = parser.parseBuffer(buf);
    assertTrue(sds.hasHeartRate());
    assertTrue(sds.getHeartRate().getState() == Sensor.SensorState.SENDING);
    assertEquals(150, sds.getHeartRate().getValue());
  }
}
